require('module-alias/register')

var { sunnyRegion, sunnyCitys, sunnyCode} = require('@Sequelize')
var { Op } = require("sequelize")

// 使用此方法，查询最深的子级结果为三层。如果能保证数据继承关系最深为三层，可以使用此方法。
// https://blog.csdn.net/weixin_34342992/article/details/91363282

async function getTree(req, res, next) {
    var exclude = []
    var data = await sunnyCitys.findAll({
        where: {
            id: '370400'
        },
        attributes: { exclude },
        include: {
            model: sunnyCitys,
            as: 'childrens',
            required: false,
            attributes: { exclude },
            include: {
                model: sunnyCitys,
                as: 'childrens',
                required: false,
                attributes: { exclude },
                include: {
                    model: sunnyCitys,
                    as: 'childrens',
                    required: false,
                    attributes: { exclude }
                }
            }
        }
    })
    res.send(JSON.stringify(data))
}

async function cetGetTree(req, res, next){
    const citysData = await sunnyCitys.findAll({ 
        where:{
            id:'100000'
        },
        include: {
            model: sunnyCitys,
            as: 'children'
        }
    });
    res.send(citysData)
}
module.exports = { getTree, cetGetTree }; 